package com.zcl.utils;

import android.text.TextUtils;
import android.util.Log;
/**
 * 打日志文件
 * 
 * @author LuoZeFeng
 * 
 */
public class NqLog {

    /**
     * 得到Exception所在代码的行数 如果没有行信息,返回-1
     */
    public static int d(Exception e, String message) {
        StackTraceElement[] trace = e.getStackTrace();
        if (TextUtils.isEmpty(message) || trace == null || trace.length == 0 || !Value.printLog) {
            return -1;
        }

        if (Value.printLog) {
            Log.d(trace[0].getMethodName(), "[ "
                    + trace[0].getFileName() + " ]," + "[ line " + trace[0].getLineNumber() + " ]," + "[ " + message + " ]");
        }
        return trace[0].getLineNumber();
    }

    public static int w(Exception e, String message) {
        StackTraceElement[] trace = e.getStackTrace();
        if (TextUtils.isEmpty(message) || trace == null || trace.length == 0 || !Value.printLog) {
            return -1;
        }

        if (Value.printLog) {
            Log.w(trace[0].getMethodName(), "[ "
                    + trace[0].getFileName() + " ]," + "[ line " + trace[0].getLineNumber() + " ]," + "[ " + message + " ]");
        }
        return trace[0].getLineNumber();
    }

    public static int e(Exception e, String message) {
        StackTraceElement[] trace = e.getStackTrace();
        if (TextUtils.isEmpty(message) || trace == null || trace.length == 0 || !Value.printLog) {
            return -1;
        }

        if (Value.printLog) {
            Log.e(trace[0].getMethodName(), "[ "
                    + trace[0].getFileName() + " ]," + "[ line " + trace[0].getLineNumber() + " ]," + "[ " + message + " ]");
        }
        return trace[0].getLineNumber();
    }

    public static void d(String message) {
        d("iweibo", message);
    }

    public static void d(String tag, String message) {
        if (Value.printLog && (!TextUtils.isEmpty(message))) {
            Log.d(tag, message);
        }
    }
}
